package models

import (
	"gitee.com/gtsoa/mspkg/config"
	"github.com/spf13/cobra"
)

type Config struct {
	Enable bool
}

func (c *Config) BindFlag(cmd *cobra.Command, prefix string) {
	config.BindBoolFlag(cmd, prefix, "server.enable", true, "enable demo")
}

func (c *Config) Parse(prefix string) config.Config {
	cfg := &Config{}
	cfg.Enable = config.GetBool(prefix, "server.enable")
	return cfg
}

func BindConfig(cmd *cobra.Command, prefixs ...string) {
	prefix := ""
	if len(prefixs) > 0 {
		prefix = prefixs[0]
	}
	(&Config{}).BindFlag(cmd, prefix)
}

func ParseConfig(prefixs ...string) *Config {
	prefix := ""
	if len(prefixs) > 0 {
		prefix = prefixs[0]
	}
	return (&Config{}).Parse(prefix).(*Config)
}
